#pragma once
#include <Rz/Object.h>
#include <Rz/Graphics/Render/IVertexArray.h>
#include "API/GLDefinitions.h"

namespace Rz { namespace Graphics { namespace Render { namespace Libraries { namespace OpenGL {

class GLVertexArray :
	public Object,
	public IVertexArray
{
	public:
		RZ_RTTI(Rz::Graphics::Render::Libraries::OpenGL, GLVertexArray);
		RZ_RTTI_IMPLEMENTS(Object, IVertexArray);
		RZ_RTTI_END;

		GLVertexArray(IRenderDevice* renderDevice);
		GLVertexArray(IRenderDevice* renderDevice, IVertexBuffer* vertexBuffer, IIndexBuffer* indexBuffer);

		virtual ~GLVertexArray();

		void Rebuild();
		bool IsDirty() const;

		// override non-const methods, because it could be used for setting new buffers
		virtual IVertexBuffer* GetVertexBuffer() override;
		virtual IIndexBuffer* GetIndexBuffer() override;
		virtual void SetVertexBuffer(IVertexBuffer* vertexBuffer) override;
		virtual void SetIndexBuffer(IIndexBuffer* indexBuffer) override;

		// IDeviceResource
		virtual void Bind() override;
		virtual void Unbind() override;

	private:
		GLuint _vertexArrayHandle;
		bool _isDirty;
};

} } } } }
